<?php
class IndexController extends Zend_Controller_Action
{
    /**
     * accessing our session variable
     * @var Zend_Session_Namespace
     */
    protected $session;


    public function init()
    {
        //get config items
        $this->config = Zend_Registry::get('config');
    }
    //Call before call the action
    public function preDispatch()
    {
        $this->session = new Zend_Session_Namespace('Default');
        /*if (isset($this->session->pageCounter))
            $this->session->pageCounter++;
        else
            $this->session->pageCounter = 0;
         */
    }

    public function indexAction()
    {
        //$this->view->message = $this->session->pageCounter;
    }


    public function countryAction()
    {
        $service = new App_HttpClient("searchuser", "mys3cr3tk3y");
    	$response = $service->call("countrysearch",array("query" => "ar"));
    	//var_dump($response);
        //$countryBusiness = new App_Countries();
        //$response = $countryBusiness->SearchCountries("un");
        echo "<pre>";
        print_r($response);
        echo "</pre>";
    }

    public function zendconfigAction()
    {
        $this->view->host = $this->config->host;
        $this->view->name = $this->config->name->first;
        $this->view->last = $this->config->name->last;
    }

    public function restAction()
    {
        $client = new Zend_Http_Client();
        $query = 'zend'; //search in twitter anything with the word "zend"
        $client->setUri("http://search.twitter.com/search.json?q=$query");
        $json = Zend_Json::decode($client->request("GET")->getBody());
        $this->view->twitterResult = $json['results'];
    }

    public function ajaxjsonAction()
    {
        
    }

    public function zendviewAction()
    {

    }

    public function viewpartialAction()
    {
        $items = array();
        $items[] = $this->newItem(1,'Pablo 1');
        $items[] = $this->newItem(2,'Pablo 2');
        $items[] = $this->newItem(3,'Pablo 3');
        $items[] = $this->newItem(4,'Pablo 4');
        $this->view->items = $items;
    }

    private function newItem($id,$name)
    {
        $item = new stdClass();
        $item->id = $id;
        $item->name = $name;
        return $item;
    }

    public function listAction()
    {
        /*
        $this->session->pageCounter += 10;
        $this->view->message = $this->session->pageCounter;

        if($this->getRequest()->getParam('users'))
        {
            $user = $this->getRequest()->getParam('users');
            $this->view->user = "User Picked: ".$user;
        }
        else
        {
            $this->view->user = 'User not selected';
        }
         */
    }
}

